var express = require('express');
var fs = require('fs');

module.exports = function(app) {
    var router = express.Router();

    router.get('/**', function(req, res, next) {
        // res.send(req.url);
        console.log('[FileServer] Fetching: ' + req.path);

        fs.readFile('./files' + req.path, function(err, data) {
            if (err) {
                res.send({ success: false, errorMsg: 'File not exist!' });
            } else {
                res.writeHead(200, {'Content-Type': 'image/jpeg'});
                res.end(data, 'binary');
            }
        });
    });

    app.use('/read', router);
}